bitkeeper revision 1.1108.2.2 (40fbf4de21Jj1rHIoB288QJ0sKILVg)
authormwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Mon, 19 Jul 2004 16:20:46 +0000 (16:20 +0000)
committermwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Mon, 19 Jul 2004 16:20:46 +0000 (16:20 +0000)
Tweak xm command parsing - can now use unambiguous prefixes to identify the
command.  For instance: 'xm list' can be 'xm l' 'xm li' 'xm lis'.

tools/python/xen/xm/main.py

index 5c1c5440739bde02a159de414dbcff1a5520ad6a..0dd523a32be34de7e4de8c8323fa072eee6dbce0 100644 (file)
@@ -105,8 +105,23 @@ class Xm:
 
     def getprog(self, name, val=None):
         """Get a sub-program.
+        name  Name of the sub-program (or optionally, an unambiguous
+              prefix of its name)
+        val   Default return value if no (unique) match is found
         """
-        return self.progs.get(name, val)
+
+        match = None
+        for progname in self.progs.keys():
+            if progname == name:
+                match = progname
+                break
+            if progname.startswith(name):
+                if not match:
+                    match = progname
+                else:
+                    return val # name is ambiguous - bail out
+
+        return self.progs.get(match, val)
 
     def proglist(self):
         """Get a list of sub-programs, ordered by group.